home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.xa;
-
- import com.extensibility.app.BaseApplication;
- import com.extensibility.app.DialogFactory;
- import com.extensibility.app.UI;
- import com.extensibility.rock.GifEncoder;
- import com.extensibility.rock.ImageEncoder;
- import com.extensibility.xml.URI;
- import com.extensibility.xml.XMLStringUtilities;
- import java.awt.Component;
- import java.awt.Image;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.StringReader;
- import java.io.Writer;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Hashtable;
- import javax.swing.JTable;
-
- public final class HtmlTableDoc implements HtmlTableDocWriter {
- protected static final String TAG_HTML_DECL = "html";
- protected static final String TAG_BODY_DECL = "body";
- protected static final String TAG_TABLE_DECL = "table";
- protected static final String TAG_TR_DECL = "tr";
- protected static final String TAG_TD_DECL = "td";
- protected static final String TAG_TH_DECL = "th";
- protected static final String TAG_CAPTION_DECL = "caption";
- protected static final String TAG_IMG_DECL = "img";
- protected static final String TABLE_TITLE = "title";
- protected static final String TAG_COMMENT_START = "<!--";
- protected static final String TAG_COMMENT_END = "-->";
- protected static final String HTML_ITEM_START = "XAitem";
- protected static final String HTML_TABLE_START = "XAtable";
- protected static final String BEFORE_TABLE = "beforeTable";
- protected static final String AFTER_TABLE = "afterTable";
- protected static final String BEFORE_TR = "beforeTr";
- protected static final String AFTER_TR = "afterTr";
- protected static final String BEFORE_TH = "beforeTh";
- protected static final String AFTER_TH = "afterTh";
- protected static final String BEFORE_TD = "beforeTd";
- protected static final String AFTER_TD = "afterTd";
- private static final String IMAGE_BASE_NAME = "XAImageFile";
- protected static final int COL_START = 2;
- protected static final int ROW_START = 0;
- private File spoolFile;
- private File templateFile;
- private int imageCount = 0;
- private Writer writer;
- private HtmlWriter htmlWriter;
- private BufferedReader inReader;
- private String tableTag;
- private String trTag;
- private String thTag;
- private String tdTag;
- private String captionTag;
- private String lineStr;
- private boolean firstTable;
- boolean hasTable = false;
-
- public HtmlTableDoc(File var1, File var2) {
- this.spoolFile = var2;
- this.templateFile = var1;
- }
-
- public File getSpoolFile() {
- return this.spoolFile;
- }
-
- public URL getSpoolURL() {
- try {
- URL var1 = new URL((new URI(this.spoolFile)).getFullName());
- return var1;
- } catch (MalformedURLException var3) {
- Object var2 = null;
- return (URL)var2;
- }
- }
-
- public void createTemplateReader() throws IOException {
- this.inReader = new BufferedReader(new FileReader(this.templateFile));
- }
-
- public void createSpoolWriter() throws IOException {
- this.writer = new FileWriter(this.spoolFile);
- this.htmlWriter = new HtmlWriter(this.writer);
- }
-
- public void writeHtmlHeader() throws IOException {
- while((this.lineStr = this.inReader.readLine()) != null && this.lineStr.indexOf("<body") == -1) {
- this.htmlWriter.writeText(this.lineStr);
- this.htmlWriter.writeLineBreak(false);
- }
-
- if (this.lineStr != null) {
- this.htmlWriter.writeText(this.lineStr);
- this.htmlWriter.writeLineBreak(false);
- }
-
- }
-
- public void scanTemplate(HtmlTableDocClient var1, String[] var2, int[] var3) {
- try {
- this.createTemplateReader();
- this.createSpoolWriter();
- this.writeHtmlHeader();
-
- while(true) {
- int var4;
- for(this.lineStr = this.inReader.readLine(); (var4 = this.lineStr.indexOf("XAitem")) == -1; this.lineStr = this.inReader.readLine()) {
- this.htmlWriter.writeText(this.lineStr);
- this.htmlWriter.writeLineBreak(false);
- }
-
- int var5 = this.findMatch(this.lineStr, var2);
- if (var5 >= 0) {
- Hashtable var6 = XMLStringUtilities.getNameValuePairs(this.lineStr.substring(var4 + "XAitem".length(), this.lineStr.indexOf("-->", var4)));
- var1.scanMatchItem(this, var6, var3[var5]);
- }
- }
- } catch (Exception var7) {
- this.flush();
- this.close();
- }
- }
-
- public void writeImage(Image var1, Hashtable var2, int var3) {
- BaseApplication.getApplication();
- File var4 = BaseApplication.getHomePath();
- StringBuffer var5 = new StringBuffer("XAImageFile");
- var5.append(this.imageCount++);
- var5.append(".gif");
- File var6 = new File(var4, var5.toString());
- ++this.imageCount;
- StringBuffer var7 = new StringBuffer("<p>");
- var7.append(var2.get("title"));
- var7.append("</p>\r\n<p>");
- var7.append("<img border=\"0\" src=\"");
- var7.append(var5);
- var7.append("\"></p>");
- this.htmlWriter.writeRawText(var7.toString());
- this.htmlWriter.writeLineBreak();
- this.htmlWriter.writeRawText("<div>");
- this.htmlWriter.writeLineBreak();
-
- try {
- FileOutputStream var8 = new FileOutputStream(var6);
- GifEncoder var9 = new GifEncoder(var1, var8);
- ((ImageEncoder)var9).setColorMangler(new ImageEncoder.BackgroundColorMangler(var3));
- ((ImageEncoder)var9).encode();
- var8.close();
- } catch (Exception var10) {
- }
-
- this.hasTable = true;
- }
-
- public void writeText(String var1) {
- this.hasTable = true;
- StringReader var2 = new StringReader(var1);
- BufferedReader var3 = new BufferedReader(var2);
-
- try {
- while(true) {
- String var4 = var3.readLine();
- this.htmlWriter.writeHtmlText(var4);
- this.htmlWriter.writeRawText("<br>");
- this.htmlWriter.writeLineBreak();
- }
- } catch (Exception var5) {
- }
- }
-
- public void writeTable(DeclTable var1, Hashtable var2) {
- this.hasTable = true;
-
- try {
- if (this.lineStr == null || var1 == null) {
- return;
- }
-
- String var3 = (String)var2.get("table");
- String var4 = (String)var2.get("tr");
- String var5 = (String)var2.get("td");
- String var6 = (String)var2.get("th");
- String var7 = (String)var2.get("caption");
- String var8 = (String)var2.get("title");
- String var9 = (String)var2.get("beforeTable");
- String var10 = (String)var2.get("afterTable");
- String var11 = (String)var2.get("beforeTh");
- String var12 = (String)var2.get("afterTh");
- String var13 = (String)var2.get("beforeTr");
- String var14 = (String)var2.get("afterTr");
- String var15 = (String)var2.get("beforeTd");
- String var16 = (String)var2.get("afterTd");
- if (var9 != null && var9.length() > 1) {
- this.htmlWriter.writeText(var9);
- this.htmlWriter.writeLineBreak(false);
- }
-
- this.htmlWriter.writeElem("table", -1);
- this.htmlWriter.writeAttr(var3, "");
- if (var13 != null && var13.length() > 1) {
- this.htmlWriter.writeText(var13);
- this.htmlWriter.writeLineBreak(false);
- }
-
- this.htmlWriter.writeElem("tr", -1);
- this.htmlWriter.writeAttr(var4, "");
-
- for(int var17 = 2; var17 < ((JTable)var1).getColumnCount(); ++var17) {
- String var18 = ((JTable)var1).getColumnName(var17);
- var18 = UI.getString(var18);
-
- try {
- this.htmlWriter.writeElem("th", -1);
- this.htmlWriter.writeAttr(var6, "");
- if (var11 != null && var11.length() > 1) {
- this.htmlWriter.writeText(var11);
- this.htmlWriter.writeLineBreak(false);
- }
-
- this.htmlWriter.writeText(var18);
- if (var12 != null && var12.length() > 1) {
- this.htmlWriter.writeText(var12);
- this.htmlWriter.writeLineBreak();
- }
-
- this.htmlWriter.flush("th");
- } catch (Exception var24) {
- DialogFactory.showException((Component)null, 128, var24, "");
- }
- }
-
- this.htmlWriter.flush("tr");
- if (var14 != null && var14.length() > 1) {
- this.htmlWriter.writeText(var14);
- this.htmlWriter.writeLineBreak(false);
- }
-
- for(int var27 = 0; var27 < ((JTable)var1).getRowCount() - 1; ++var27) {
- if (var13 != null && var13.length() > 1) {
- this.htmlWriter.writeText(var13);
- this.htmlWriter.writeLineBreak(false);
- }
-
- this.htmlWriter.writeElem("tr", -1);
- this.htmlWriter.writeAttr(var4, "");
-
- for(int var19 = 2; var19 < ((JTable)var1).getColumnCount(); ++var19) {
- this.htmlWriter.writeElem("td", -1);
- this.htmlWriter.writeAttr(var5, "");
- if (var15 != null && var15.length() > 1) {
- this.htmlWriter.writeText(var15);
- this.htmlWriter.writeLineBreak(false);
- }
-
- Object var20 = ((JTable)var1).getValueAt(var27, var19);
- String var21 = "";
- if (var20 != null) {
- var21 = var20.toString();
- }
-
- if (var21.equals("false")) {
- var21 = "";
- } else if (var21.equals("true")) {
- var21 = "X";
- }
-
- if (var21.equals("")) {
- this.htmlWriter.writeText("<pre> </pre>");
- } else {
- try {
- this.htmlWriter.writeText(var21);
- } catch (Exception var23) {
- DialogFactory.showException((Component)null, 128, var23, "");
- }
- }
-
- if (var16 != null && var16.length() > 1) {
- this.htmlWriter.writeText(var16);
- this.htmlWriter.writeLineBreak(false);
- }
-
- this.htmlWriter.flush("td");
- }
-
- this.htmlWriter.flush("tr");
- if (var14 != null && var14.length() > 1) {
- this.htmlWriter.writeText(var14);
- this.htmlWriter.writeLineBreak(false);
- }
- }
-
- this.htmlWriter.flush("table");
- if (var10 != null && var10.length() > 1) {
- this.htmlWriter.writeText(var10);
- this.htmlWriter.writeLineBreak(false);
- }
- } catch (Exception var25) {
- DialogFactory.showException((Component)null, 128, var25, "");
- this.close();
- }
-
- }
-
- public void flush() {
- this.htmlWriter.flush();
-
- try {
- while((this.lineStr = this.inReader.readLine()) != null) {
- this.htmlWriter.writeText(this.lineStr);
- this.htmlWriter.writeLineBreak(false);
- }
- } catch (Exception var2) {
- DialogFactory.showException((Component)null, 128, var2, "");
- }
-
- }
-
- public boolean hasTable() {
- return this.hasTable;
- }
-
- public void close() {
- try {
- this.inReader.close();
- this.writer.close();
- } catch (IOException var2) {
- DialogFactory.showException((Component)null, 128, var2, "");
- }
-
- }
-
- private int findMatch(String var1, String[] var2) {
- int var3 = var2.length;
- int var4 = -1;
-
- for(int var5 = 0; var5 < var3 && var4 < 0; ++var5) {
- if (var1.indexOf(var2[var5]) != -1) {
- var4 = var5;
- }
- }
-
- return var4;
- }
- }
-